package view
{
	import flash.events.Event;
	
	import model.Enseignant;
	import model.Utilisateur;
	import model.proxy.LoginProxy;
	
	import mx.controls.Alert;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;
	
	import view.components.LoginPanel;
	
	public class LoginPanelMediator extends Mediator implements IMediator
	{
		 public function LoginPanelMediator(viewComponent : LoginPanel) 
		 { 
			super(NAME, viewComponent); 
			viewComponent.addEventListener(LoginPanel.IDENT, identificationNotification);
		 }
		 
		 private function identificationNotification(event : Event=null):void 
		 { 
			 var utilisateur:Utilisateur = new Utilisateur(); 
			 utilisateur.login = loginPanel.login.text;
			 utilisateur.mdp = loginPanel.pass.text;
			 sendNotification(LoginPanel.IDENT, utilisateur); 
		 }
		 
		 override public function listNotificationInterests():Array 
		 { 
		 	return [ LoginProxy.AUTHENTIFICATION ]; 
		 } 
 
		 override public function handleNotification(note : INotification):void 
		 { 
			 switch (note.getName()) 
			 { 
			 	case LoginProxy.AUTHENTIFICATION:
			 	{
			 		//Alert.show( ((note.getBody() as Utilisateur).aEnseignant as Enseignant).nom);
					loginPanel.dispatchEvent(new Event("ihmAdminPanel"));
					loginPanel.dispatchEvent(new Event("menuUser"));
					
			 		break;
				 }
					
			 	default:
			 	break;
		 	} 
		 }
		 
		 /** 
		 * Get the loginPanel component 
		 */ 
		 private function get loginPanel():LoginPanel 
		 { 
		 	return viewComponent as LoginPanel; 
		 }

	}
}